package com.wjx.article_sys.dao;

import com.wjx.article_sys.entity.Article;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleMapper {
    //查询所有文章
    @Select("select * from Article order by artid desc")
    public List<Article> queryAllArticle();
    //根据id查询文章
    @Select("select * from Article where artid = #{id}")
    public Article queryArticleById(Integer id);

    //根据标题查询文章
    @Select("select * from Article where Title = #{title}")
    public Article queryArticleByTitle(String title);
    //添加文章
    @Insert("insert into Article(Title,Content,Author,Posttime)" +
            " values(#{title},#{content},#{author},#{postTime})")
    public void addArticle(String title,String content,String author,String postTime);
    //根据id修改文章
    @Update("update Article set Title = #{title},Content = #{content} where artid = #{id}")
    public void updateArticleById(Integer id,String title,String content);

    //根据id删除文章
    @Delete("delete from Article where artid = #{id}")
    public void deleteArticleById(Integer id);

    //根据文章总数
    @Select("select count(*) from Article ")
    public Integer articleAllCount();

    //根据用户名查询文章数量
    @Select("select count(*) from Article where Author = #{author}")
    public  Integer countArticleByAuthor(String author);
}
